<?php
    /**
     * User zgh
     * Email 1803897171@qq.com
     * Date 2021/8/4
     **/

    namespace app\admin\controller;

    use app\common\Annotation\ControllerAnnotation;
    use app\common\Annotation\NodeAnotation;
    use app\admin\service\QuickMenuService;
    use app\common\controller\BackendController;
    use app\common\model\QuickMenuModel;
    use think\facade\Request;


    /**
     * Class MenuController
     * @ControllerAnnotation(title="快捷入口",auth=2)
     * @package app\admin\controller
     */
    class QuickMenuController extends BackendController
    {

        /**
         * @NodeAnotation(title="列表")
         * @return mixed|\think\response\Json
         */
        public function index()
        {
            if (Request::isAjax()) {
                $res = QuickMenuService::getList(Request::param());
                return success_json_response("成功", $res['dataList'], ['count' => $res['count']]);
            } else {
                return $this->fetch();
            }
        }

        /**
         * @NodeAnotation(title="添加")
         * @return mixed|\think\response\Json
         * @throws \app\common\exception\ServiceException
         */
        public function add()
        {
            $params = Request::param();
            if (Request::isAjax()) {
                $res = QuickMenuService::save($params);
                if ($res) {
                    return success_json_response("修改成功", ["id" => $res]);
                } else {
                    return json_response("修改失败");
                }
            }
            return $this->fetch();
        }

        /**
         * @NodeAnotation(title="修改")
         * @return mixed|\think\response\Json
         * @throws \app\common\exception\ServiceException
         */
        public function edit()
        {
            $params = Request::param();
            if (Request::isAjax()) {
                $res = QuickMenuService::save($params);
                return $res ? success_json_response("修改成功", ["id" => $res]) : json_response("修改失败");
            }
            $model = QuickMenuModel::get($params['id']);
            $this->assign("model", $model);
            return $this->fetch();
        }

        /**
         * @NodeAnotation(title="删除")
         * @return \think\response\Json
         * @throws \app\common\exception\ServiceException
         */
        public function del()
        {
            if (Request::isAjax()) {
                $res = QuickMenuService::del(Request::param());
                return $res ? success_json_response("删除成功") : json_response("删除失败");
            }
        }


    }